/// <reference path="../../../index.d.ts" />
const Controller = require("egg").Controller
let {sendStat} = require("../../extend/helper")
class StaticData extends Controller {
	constructor(ctx) {
		super(ctx)
		this.constant = this.config.constant
		this.Leaderboard = this.ctx.model.Game.Leaderboard
		this.ShopCount = this.ctx.model.GameView.ShopCount
	}
	async  getWorldRankList() {
		let border = await this.app.cache.leaderboard
		let oid = this.ctx.userInfo.oid
		let gameUser = this.ctx.gameUser
		let userInfo = await this.ctx.service.wechatUser.getUserBaseInfo(oid)
		let count = await this.ShopCount.findOne({
			where: {
				oid
			}
		})
		let index = await this.Leaderboard.count({
			where: {
				total_coin: {
					$gt: gameUser.total_coin
				}
			}
		})
		this.ctx.body = sendStat(this.constant.NORMAL, {
			world: border, self: {
				id: oid, 
				total_coin: gameUser.total_coin,
				avatar: userInfo.avatar,
				index: index + 1, 
				count: count && count.count,
				nickName: userInfo.nickName,
			}
		})
	}
}
module.exports = StaticData